﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;

namespace RestFulService
{
    public class Global
    {
        /* 
        
         公用类定义:用户编号，用户姓名，用户权限，连接信息，门店编号，POS号，打印机信息等
         
         */

        //是否启动mqtt
        public int starmqtt;
        //是否启动redis
        public int starredis;
        //是否启动sqlite
        public int starsqlite;

        //sqlite产生目录
        private string path1;

        //构造函数
        public Global()
        {
            string str = System.Environment.CurrentDirectory + "\\WINBOX.ini";
            IniFile ini = new IniFile(str);
            starmqtt =int.Parse(ini.IniReadValue("system", "starmqtt"));
            starredis = int.Parse(ini.IniReadValue("system", "starredis"));
            starsqlite = int.Parse(ini.IniReadValue("system", "starsqlite"));
            path1 = ini.IniReadValue("system", "path1");
        }

        public void doSetDB()
        {
            //产生sqlite数据库 ，并填入数据
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "star sqlite...");
            DBSERVER myADO = new DBSERVER();

            SQLiteDBHelper mysqlite = new SQLiteDBHelper();

            try
            {
                string SQL = "select fOrgNo from VIEW_SQLITE_STORE where 1=1 order by fOrgNo";
                DataTable dtStore = myADO.query(SQL);
                for (int m = 0; m < dtStore.Rows.Count; m++)
                {
                    string sOrgNo = dtStore.Rows[m]["fOrgNo"].ToString();

                    mysqlite.CreateDB(sOrgNo, path1, myADO);

                }
                
                myADO.Close();
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "over sqlite...");
            }
            catch (Exception ex)
            {
                Console.WriteLine("出错:" + ex.Message);
            }
        }

    }
}
